<?php

namespace App\Http\Controllers\Admin;

use App\Models\Cities;
use App\Models\Fangattr;
use App\Models\FangOwners;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class BaseController extends Controller
{
    protected $pagesize = 10;
    public function __construct()
    {
        $this->pagesize = config('page.pagesize');
    }

    //添加和修改关联数据
    public function relationData(){
        //取关联数据
        //获取当前平台的所有业主【用作选择】
        $ownerData = FangOwners::get();
        //获取省份数据【用作选择】
        $cityData = Cities::where('pid', 0)->get();
        //获取租期方式
        $fang_rent_type_id = Fangattr::where('field_name', 'fang_rent_type')->value('id');
        $fang_rent_type_data = Fangattr::where('pid', $fang_rent_type_id)->get();
        //获取房源朝向
        $fang_direction_id = Fangattr::where('field_name', 'fang_direction')->value('id');
        $fang_direction_data = Fangattr::where('pid', $fang_direction_id)->get();
        //租赁方式
        $fang_rent_class_id = Fangattr::where('field_name', 'fang_rent_class')->value('id');
        $fang_rent_class_data = Fangattr::where('pid', $fang_rent_class_id)->get();
        //配套设施
        $fang_config_id = Fangattr::where('field_name', 'fang_config')->value('id');
        $fang_config_data = Fangattr::where('pid', $fang_config_id)->get();
        $data = [
            'ownerData' => $ownerData,
            'cityData' => $cityData,
            'fang_rent_type_data' => $fang_rent_type_data,
            'fang_direction_data' => $fang_direction_data,
            'fang_rent_class_data' => $fang_rent_class_data,
            'fang_config_data' => $fang_config_data
        ];
        return $data;
    }
}
